package com.example.red_tea_house.moudle.LoginAndRegister.model;

import android.content.Context;

import com.example.red_tea_house.MyApplication;
import com.example.red_tea_house.entity.LoginBean;
import com.example.red_tea_house.moudle.LoginAndRegister.controller.GetVertifyController;
import com.example.red_tea_house.util.ToastUtil;


public class LegalData {
    private String phone;
    private String password;

    Context context= MyApplication.getContext();

    public boolean isLegalData(LoginBean loginBean){
        phone=loginBean.getPhone();
        password=loginBean.getPassword();
        if(legalPhone()&&legalPassword())
            return true;
        return false;
    }
    public boolean isLegalData(LoginBean loginBean,String password2){
        phone=loginBean.getPhone();
        password=loginBean.getPassword();
        if(password.equals(password2)){
            if(legalPassword()&&legalPhone()){
                return true;
            }
        }else{
            ToastUtil.showToast(context, "两次密码不同，请修改");
            return false;
        }
        return false;
    }

    private boolean legalPhone(){
        if(phone.length()==0){
            ToastUtil.showToast(context,"未填写手机号，请输入手机号");
            return false;
        }
        if(phone.length() != 11){
            ToastUtil.showToast(context,"手机号格式错误，请重新输入");
            return false;
        }
        return true;
    }
    private boolean legalPassword(){
        if(password.length()==0){
            ToastUtil.showToast(context,"密码为空，请输入密码");
            return false;
        }
        if(password.length()<6){
            ToastUtil.showToast(context,"密码不能少于6位");
            return false;
        }
        return true;
    }
}
